Source for file RenameFile.php

Documentation is available at RenameFile.php

  1. <?php /*
  2.  * FCKeditor - The text editor for internet
  3.  * Copyright (C) 2003-2005 Frederico Caldeira Knabben
  4.  * 
  5.  * Licensed under the terms of the GNU Lesser General Public License:
  6.  *         http://www.opensource.org/licenses/lgpl-license.php
  7.  * 
  8.  * For further information visit:
  9.  *         http://www.fckeditor.net/
  10.  * 
  11.  * File Name: RenameFile.php
  12.  *     Implements the DeleteFile command to delete a file
  13.  *     in the current directory. Output is in XML
  14.  * 
  15.  * File Authors:
  16.  *         Grant French (grant@mcpuk.net)
  17.  */
  18. class RenameFile {
  19.     var $fckphp_config;
  20.     var $type;
  21.     var $cwd;
  22.     var $actual_cwd;
  23.     var $newfolder;
  24.     
  25.     function RenameFile($fckphp_config,$type,$cwd{
  26.         $this->fckphp_config=$fckphp_config;
  27.         $this->type=$type;
  28.         $this->raw_cwd=$cwd;
  29.         $this->actual_cwd=str_replace("//","/",($fckphp_config['UserFilesPath']."/$type/".$this->raw_cwd));
  30.         $this->real_cwd=str_replace("//","/",($this->fckphp_config['basedir']."/".$this->actual_cwd));
  31.         $this->filename=str_replace(array("..","/"),"",$_GET['FileName']);
  32.         $this->newname=str_replace(array("..","/"),"",$this->checkName($_GET['NewName']));
  33.     }
  34.     
  35.     function checkName($name{
  36.         $newName="";
  37.         for ($i=0;$i<strlen($name);$i++{
  38.             if (in_array($name[$i],$this->fckphp_config['FileNameAllowedChars'])) $newName.=$name[$i];
  39.         }
  40.         return $newName;
  41.     }
  42.     
  43.     function run({
  44.         $result1=false;
  45.         $result2=true;
  46.         
  47.         if ($this->newname!=''{
  48.         
  49.             if ($this->nameValid($this->newname)) {
  50.                 //Remove thumbnail if it exists
  51.                 $result2=true;
  52.                 $thumb=$this->real_cwd.'/.thumb_'.$this->filename;
  53.                 if (file_exists($thumb)) $result2=unlink($thumb);
  54.                 
  55.                 $result1=rename($this->real_cwd.'/'.$this->filename,$this->real_cwd.'/'.$this->newname);
  56.             else {
  57.                 $result1=false;
  58.             }
  59.         }
  60.         
  61.         header ("content-type: text/xml");
  62.         echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
  63.         ?>
  64. <Connector command="RenameFile" resourceType="<?php echo $this->type?>">
  65.     <CurrentFolder path="<?php echo $this->raw_cwd?>" url="<?php echo $this->actual_cwd?>" />
  66.     <?php
  67.         if ($result1&&$result2{
  68.             $err_no=0;
  69.         else {
  70.             $err_no=502;
  71.         }
  72.     ?>
  73.     <Error number="<?php echo "".$err_no?>" />
  74. </Connector>
  75.         <?php
  76.     }
  77.     
  78.     function nameValid($fname{
  79.         $type_config=$this->fckphp_config['ResourceAreas'][$this->type];
  80.         
  81.         $lastdot=strrpos($fname,".");
  82.             
  83.         if ($lastdot!==false{
  84.             $ext=substr($fname,($lastdot+1));
  85.             $fname=substr($fname,0,$lastdot);
  86.                 
  87.             if (in_array(strtolower($ext),$type_config['AllowedExtensions'])) {
  88.                 return true;
  89.             else {
  90.                 return false;
  91.             }
  92.         }
  93.     }
  94. }
  95.  
  96. ?>

Documentation generated on Mon, 05 May 2008 16:22:38 +0400 by phpDocumentor 1.4.0